package com.iwhalecloud.bss.kite.cucc.manager.scene.service.query;

import com.iwhalecloud.bss.kite.manager.enums.InstType;
import com.iwhalecloud.bss.kite.manager.inst.KiteOfferInstAcct;
import com.iwhalecloud.bss.kite.manager.inst.KiteSceneInst;
import com.iwhalecloud.bss.kite.manager.inst.graph.impl.InstVertex;
import com.iwhalecloud.bss.kite.manager.scene.service.query.QueryInstService;
import com.iwhalecloud.bss.kite.manager.scene.util.InstUtils;
import com.iwhalecloud.bss.kite.manager.scene.util.SceneInstUtils;
import com.iwhalecloud.bss.kite.manager.transaction.TransactionContext;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 销售品关联账户实例查询类
 */
@Service("manager.localQueryOfferInstAcctRelService")
public class LocalQueryOfferInstAcctRelService extends QueryInstService {

    /**
     * 获取所有销售品关联账户实例
     * @param sceneInstId
     * @return
     */
    public List<KiteOfferInstAcct> listOfferInstAcctRels(String sceneInstId) {
        KiteSceneInst sceneInst = TransactionContext.getContainer().getSceneInst(sceneInstId);
        String custId = SceneInstUtils.getCustId(sceneInst);
        List<InstVertex> instVertexs = SceneInstUtils.listInstVertexs(sceneInst, InstType.OFFER_INST_ACCT);
        return InstUtils.transformInsts(custId, instVertexs);
    }

    /**
     * 获取销售品实例的所有账户实例
     * @param custId
     * @param prodInstId
     * @return
     */
    public List<KiteOfferInstAcct> listOfferInstAcctRels(String custId, String offerInstId, InstType offerInstType) {
        /*IInstRelGraph custInstRelGraph = TransactionContext.getContainer().getCustInstRelGraph(custId);
        InstVertex instVertex = InstRelGraphUtils.getCustInstVertex(custId, offerInstType, offerInstId);
        if (Objects.isNull(instVertex)) {
            ErrorConsts.OFFER_INST_NOT_EXIST.throwOut(offerInstId, custId);
        }

        if (instVertex instanceof ISubOfferInstAcct) {
            ((ISubOfferInstAcct) instVertex).listSubOfferInstAccts(custInstRelGraph);
        }

        List<InstVertex> instVertexs = InstRelGraphUtils.listSubInstVertexs(custInstRelGraph, instVertex,
            RelType.OFFER_ACCT_REL_TYPE_1000, InstType.OFFER_INST_ACCT_REL);*/
        return InstUtils.transformInsts(custId, null);
    }
}
